| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- import { NextResponse } from "next/server";
- import smbClient from "@/lib/smbClient";
- export async function GET(_, { params }) {
- const { path: pathArray = [] } = params;
- let smbPath = pathArray.join("\\");
- console.log("Versuche, folgende Datei zu öffnen:", smbPath);
- return new Promise((resolve, reject) => {
- smbClient.readFile(smbPath, async (err, file) => {
- if (err) {
- console.error("Fehler beim Zugriff auf die Datei:", err);
- let errorMessage = "Fehler beim Zugriff auf die Datei";
- if (err.code === "ENOENT") {
- errorMessage = "Datei nicht gefunden";
- } else if (err.code === "EACCES") {
- errorMessage = "Zugriff verweigert";
- }
- reject(
- NextResponse.json(
- {
- error: errorMessage,
- details: err.message,
- },
- { status: 500, headers: { "Cache-Control": "no-store" } }
- )
- );
- } else {
- console.log("Erfolgreicher Zugriff auf die Datei:", smbPath);
- // Rückgabe der Datei mit Cache-Control und Content-Disposition Header
- resolve(
- new NextResponse(file, {
- status: 200,
- headers: {
- "Content-Type": "application/pdf",
- "Cache-Control": "no-store",
- "Content-Disposition": "inline", // PDF im Browser anzeigen
- },
- })
- );
- }
- });
- });
- }
|